package com.suoluo.zenadmin.dao.news;

import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;

import com.suoluo.zenadmin.vo.news.News2VO;

@DAO
public interface NewsDAO {

	@SQL("select * from tb_news2  order by news_id desc limit :1,:2")
	public List<News2VO> findSimplestNews(int curPage, int pageRows);
	@ReturnGeneratedKeys
	@SQL("insert into tb_news2(zhname,enname,feature_category_id,summary,news_source," +
			"news_date,country_id,editor,viewnum) values(:1.zhname,:1.enname,:1.featureCategoryId," +
			":1.summary,:1.newsSource,:1.newsDate,:1.countryId,:1.editor,:1.viewnum)")
	public int saveNews(News2VO newsVO);

	@SQL("select * from tb_news2 t1 " +
			"join tb_base_info t2 on t1.news_id = t2.data_id and t2.info_type = :2 and t2.default_info = 1 " +
			"join tb_image t3 on t3.image_id = t1.image_id where news_id = :1")
	public News2VO findNewsById(int newsId,int infoType);

	@SQL("update tb_news2 set zhname=:1.zhname,enname=:1.enname,feature_category_id=:1.featureCategoryId," +
			"summary=:1.summary,news_source=:1.newsSource," +
			"country_id=:1.countryId,editor=:1.editor,viewnum=:1.viewnum"
			+ " where news_id=:1.newsId")
	public void updateNews(News2VO news);

	@SQL("delete from tb_news2 where news_id=:1")
	public void deleteNews(int newsId);
	@SuppressWarnings("rawtypes")
	@SQL("select t_feature_category_id featureCategoryId,t_feature_category_name featureCategoryName " +
			" from tb_dest_feature_category where t_feature_category_id != 5")
	public List<Map> findListNewsType();
	
	@SQL("select count(*) from tb_news2")
	public int findNewsCount();
	
	@SQL("select * from tb_news2 t1 join tb_image t3 on t3.image_id = t1.image_id " +
			"order by t1.news_id desc limit :1,:2")
	public List<News2VO> findNewsWithoutContent(int startPos, int endPos);
	
	@SQL("select * from tb_news2 t1 join tb_image t2 on t1.image_id = t2.image_id where news_id <> :1 " +
							"and feature_category_id = :2 order by news_id desc limit 0,:3")
	public List<News2VO> findSimilarNews(int newsId, int newsType, int pageSize);
	
	@SQL("update tb_news2 set image_id=:2 where news_id=:1")
	public void updateNewsImage(int newsId,int imageId);
	
	@SQL("update tb_news2 set viewnum=viewnum+1 where news_id=:1")
	public void updateIncrementNewsViewnum(int newsId);
	
//	@SQL("select * from tb_base_info tb " +
//			"join tb_image ti on ti.info_id=tb.info_id where tb.data_id =:1 and tb.info_type=:2")
//	public List<BaseInfoVO> findSubNews(int newsId,int infoType);
	
	@SQL("select * from tb_news where news_id = :1")
	public News2VO findSimplestNewsById(int newsId);
	
}

